package sanshui.system.trade.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sanshui.system.trade.common.TradeType;
import sanshui.system.trade.db.entity.TradeHisOpPos;
import sanshui.system.trade.db.entity.TradeHisOpPosExample;
import sanshui.system.trade.db.mapper.TradeHisOpPosMapper;
import sanshui.system.trade.factory.data.DataMarketType;
import sanshui.system.trade.model.PositionAccModel;
import sanshui.system.trade.util.CommonTimeUtil;
import sanshui.system.trade.util.TradePositionUtil;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class TradeHisOpPosServiceImpl implements ITradeHisOpPosService{

    @Resource
    TradeHisOpPosMapper tradeHisOpPosMapper;

    @Override
    public Map<String, PositionAccModel> selectAccWorkerHoldPosModels(Long workerId, Long accId, String datetime16, DataMarketType dataMarketType){
        TradeHisOpPosExample example = new TradeHisOpPosExample();
        TradeHisOpPosExample.Criteria criteria = example.createCriteria();
        if (null != accId){
            criteria.andAccIdEqualTo(accId);
        }
        if (null != workerId){
            criteria.andWorkerIdEqualTo(workerId);
        }
        criteria.andDelFlgEqualTo(TradeType.DelFlg.EXIT.getCode());
        if (DataMarketType.T1.compareTo(dataMarketType) == 0){
            return TradePositionUtil.parsePosHisToHoldInT1(new HashMap<>(), tradeHisOpPosMapper.selectByExample(example), datetime16);
        }
        return TradePositionUtil.parsePosHisToHoldInT1(new HashMap<>(),tradeHisOpPosMapper.selectByExample(example), datetime16);
    }

    @Override
    public Map<String, PositionAccModel> selectAccHoldPosModels(Long accId, String datetime16) {
        return this.selectAccWorkerHoldPosModels(null, accId, datetime16, DataMarketType.T1);
    }

    @Override
    public Map<String, PositionAccModel> selectWorkerHoldPosModels(Long workerId, String datetime16) {
        return this.selectAccWorkerHoldPosModels(workerId, null, datetime16, DataMarketType.T1);
    }

    @Override
    public Long getHoldPosValue(Long accId) {
        Map<String, PositionAccModel> modelList = this.selectAccHoldPosModels(accId, CommonTimeUtil.getNowTime16());
        return null;
    }
}
